//
//  DYZContactBackController.m
//  DYZCars
//
//  Created by MF on 16/8/20.
//  Copyright © 2016年 MF. All rights reserved.
//

#import "DYZContactBackController.h"
#import "UIColor+Addition.h"
#import "UIButton+Addition.h"
#import "UILabel+Addition.h"

@interface DYZContactBackController ()
@property (nonatomic,weak) UIButton *btn;
@property (nonatomic,weak) UIView *lineView;
@property (nonatomic, weak)UIView *detailView;
@end

@implementation DYZContactBackController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    UIButton *feedbackBtn = [[UIButton alloc]init];
    [feedbackBtn setTitle:@"意见反馈" forState:UIControlStateNormal];
    [feedbackBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.view addSubview:feedbackBtn];
    self.btn = feedbackBtn;
    UIButton *callBtn = [[UIButton alloc]init];
    //按钮的点击事件
    [callBtn addTarget:self action:@selector(moveRight:) forControlEvents:UIControlEventTouchUpInside];
    [feedbackBtn addTarget:self action:@selector(moveLeft:) forControlEvents:UIControlEventTouchUpInside];
    [callBtn setTitle:@"客服电话" forState:UIControlStateNormal];
     [callBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.view addSubview:callBtn];
    [feedbackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.width.offset(self.view.bounds.size.width*0.5);
        make.top.equalTo(self.mas_topLayoutGuideBottom);
    }];
    [callBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view);
        make.top.equalTo(self.mas_topLayoutGuideBottom);
        make.width.equalTo(feedbackBtn);
    }];
    UIView *lineView = [[UIView alloc]init];
    lineView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:lineView];
    self.lineView = lineView;
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.btn.mas_bottom);
        make.height.offset(2);
        make.width.equalTo(self.btn);
        make.centerX.equalTo(self.btn);
    }];
    UIView *detailView = [[UIView alloc] init];
    [self.view addSubview:detailView];
    [detailView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.top.equalTo(lineView.mas_bottom);
    }];
    self.detailView = detailView;

    [self moveLeft:feedbackBtn];
}
- (void)moveLeft:(UIButton *)sender{
    [self.detailView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    if (self.lineView.center.x != sender.center.x) {
        [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(sender.mas_bottom);
            make.height.offset(2);
            make.width.equalTo(sender);
            make.centerX.equalTo(sender);
        }];
    }
    UITextView *textView = [[UITextView alloc] init];
    textView.backgroundColor = [UIColor colorWithHex:0xa6a6a6];
    
    [self.detailView addSubview:textView];
    [textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(20);
        make.right.offset(-20);
        make.height.offset(200);
        make.top.equalTo(self.lineView.mas_bottom).offset(20);
    }];
    UIButton *submitBtn = [UIButton buttonWithText:@"提交" andTextColor:[UIColor whiteColor] backgroundColor:[UIColor colorWithHex:0x0073dd] andFontSize:20];
    [self.detailView addSubview:submitBtn];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(30);
        make.right.offset(-30);
        make.top.equalTo(textView.mas_bottom).offset(56);
        make.height.offset(40);
    }];
    
}

- (void)moveRight:(UIButton *)sender{
     [self.detailView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    if (self.lineView.center.x != sender.center.x) {
        [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(sender.mas_bottom);
            make.height.offset(2);
            make.width.equalTo(sender);
            make.centerX.equalTo(sender);
        }];
    }
    UILabel *phoneLabel = [UILabel labelWithText:@"我们的客服电话是：010-64642652" andTextColor:[UIColor colorWithHex:0x333333] andFontSize:14];
    [self.detailView addSubview:phoneLabel];
    [phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.detailView);
        make.top.offset(86);
    }];
    UIButton *submitBtn = [UIButton buttonWithText:@"拨打客服" andTextColor:[UIColor whiteColor] backgroundColor:[UIColor colorWithHex:0x0073dd] andFontSize:20];
    [self.detailView addSubview:submitBtn];
    [submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(30);
        make.right.offset(-30);
        make.top.equalTo(phoneLabel.mas_bottom).offset(84);
        make.height.offset(40);
    }];
   
    
}



@end
